I believe racism and religion is innate in people. They both stem from long, evolutionary processes that have been proven quite helpful in the past. This has been proven in young children, even controlling for a range of factors such as education and personal beliefs of the parents.
The explanation is quite simple: If you are in an area with low resources, you find out grouping is beneficial, but too large a group is not. So you make a small group, you need to keep them together so you make up stories about the darkness outside the range of the campfire, this fear of the darkness is quite natural, because people that wander out there are more likely to get eaten => religion is born.
So you have a small group, there isn't enough resources to grow the group, you find another group, you kill them. Now you are sentient enough to know killing is wrong, because killing within your group is bad for survival (you kill the hunter, you starve, you kill the healer, you get sepsis), but you just killed others that act and look like you. So you come up with stories about how they are "different", "less human" => Now tribalism is born, racism is just a form of tribalism.
These things have been tested in groups of young children and both close and remote ancestors of primates. Groups form when there is sufficient resources but too much danger for individuals. Tribalism forms when there is a shortage of resources for a larger group.
Kids tend to share and form groups as long as there are enough toys. When you take away some toys so they don't have enough for everyone, kids will start to form groups and fight, those groupings don't necessarily make sense, but generally along the lines of observation, how they look, race, gender, smell, even clothing items, clothing colors etc. As kids get older, they make more nuanced distinctions and come up with more elaborate stories about these distinctions.